package com.zret.oasys.operation.leave;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zret.oasys.dbtools.PageData;
import com.zret.oasys.entity.Emp;
import com.zret.oasys.entity.Leavedetails;
import com.zret.oasys.json.entity.GetTableDataJson;

public class LeavApprovalList implements LeaveServletOperation {

	@Override
	public void doOperation(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 编码设置
		request.setCharacterEncoding("utf-8");
		response.setContentType("application/json;charset=utf-8");
		// 输出流
		PrintWriter out = response.getWriter();
		// gson格式化对象
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
		// 待查找的请假单列表
		PageData<Leavedetails> pd = null;
		// 获取用户查找的类型(审批, 未审批, 全部)
		String searchType = "all";
		if(request.getParameter("searchType")!=null) {
			searchType = request.getParameter("searchType");
		}
		// 获取当前用户编号
		int empid = Integer.valueOf(request.getParameter("empid"));
		// 获取需要查找的分页信息
		int page = Integer.valueOf(request.getParameter("page"));
		int pageSize = Integer.valueOf(request.getParameter("limit"));
		// 获取要查询的员工名
		String empname = "";
		if(request.getParameter("empname") != null) {
			empname = request.getParameter("empname");
		}
		// 根据用户的选取情况调用不同的searvice方法
		pd = leaveService.getLeavemsg(empid, page, pageSize, empname, searchType);
		// 测试控制台输出看看值
		String testObj = gson.toJson(pd.getData());
		System.out.println(testObj);
		// 格式化输出到表格
		GetTableDataJson<Leavedetails> tableObj = new GetTableDataJson<Leavedetails>(0, "", pd.getTotalCount(), pd.getData());
		String jsonObj = gson.toJson(tableObj);
		System.out.println(jsonObj);
		out.print(jsonObj);
		out.close();
	}

}
